home *** CD-ROM | disk | FTP | other *** search
/ QRZ! Ham Radio 5 / QRZ Ham Radio Callsign Database - Volume 5.iso / files / amiga / csrc720j.lzh / fx.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-04-17  |  3.0 KB  |  117 lines

  1. /* fx. Send a command to SYSOP via AREXX and store the resulting output
  2.    into a file.
  3. */
  4. #include "rexxhostbase.h"
  5. #include <stdio.h>
  6.  
  7. struct RexxHostBase  *RexxHostBase;
  8.  
  9. struct RexxHost      *rexx_host;
  10. long rexxbit = 0L;
  11. char *portname = "test-rexx";
  12. /* Try to open the rexxhost.library. */
  13. open_rexx()
  14. {
  15.    if(!(RexxHostBase = (struct RexxHostBase *)
  16.              OpenLibrary((UBYTE *)REXXHOSTNAME,(long)REXXHOSTMINIMUM))) {
  17.       printf("couldn't open rexxhost library.\n");
  18.       return(1);
  19.    }
  20.  
  21.       /* set up a public port for rexx to talk to us later */
  22.    if(!(rexx_host = CreateRexxHost((STRPTR)portname)))   {
  23.       printf("Can't set up public rexx port for port %c\n",portname);
  24.       CloseLibrary((struct Library *)RexxHostBase);
  25.       return(1);
  26.    }
  27.    rexxbit = (1L << rexx_host->rh_Port.mp_SigBit);
  28.    return(0);
  29. }
  30. close_rexx()
  31. {
  32.    struct RexxMsg *rexxmessage;  /* incoming rexx messages */
  33.    STRPTR Arg;
  34.  
  35. /* Drain any messages for us */
  36.    while(rexxmessage = GetRexxMsg(rexx_host,0L)) {
  37.       if(Arg = GetRexxCommand(rexxmessage)) {
  38.          ReplyRexxCommand(rexxmessage,0L,0L,0L);
  39.       }
  40.       else {
  41.          FreeRexxCommand(rexxmessage);
  42.       }
  43.    }
  44.    if(rexx_host)
  45.       rexx_host = DeleteRexxHost(rexx_host);
  46.  
  47.    if(RexxHostBase)
  48.       CloseLibrary((struct Library *)RexxHostBase);
  49. }
  50. char cmdstr[100];
  51. FILE *fdo;
  52. main(argc,argv)
  53. int argc;
  54. char *argv[];
  55. {
  56.    struct RexxMsg *rexxmessage;  /* incoming rexx messages */
  57.    STRPTR Arg;
  58.  
  59.    if(argc < 3) {
  60.       printf("Missing argument(s). Send a message to SYSOP via AREXX\n");
  61.       printf("fx filename C-BBS command\n");
  62.       exit(10);
  63.    }
  64.    if(open_rexx()) {
  65.       printf("Can't open rexxhostlib\n");
  66.       exit(10);
  67.    }
  68.    if((fdo = fopen(argv[1],"w")) == NULL) {
  69.       printf("Can't open %s\n",argv[1]);
  70.       exit(10);
  71.    }
  72.    if(SendRexxMsg((STRPTR)"CBBS-1",0L,(STRPTR)"GO test-rexx",0L)) {
  73.       printf("SendRexxMsg - GO failed");
  74.       fclose(fdo);
  75.       exit(10);
  76.    }
  77.    /* Remove the first SYSOP> prompt */
  78.    Wait(rexxbit);
  79.    rexxmessage = GetRexxMsg(rexx_host,0L);
  80.    ReplyRexxCommand(rexxmessage,0L,0L,0L);
  81.    /* Now put together the command and send it to SYSOP */
  82.    argc--;
  83.    argv++;
  84.    while(1) {
  85.       strcat(cmdstr,argv[1]);
  86.       argc--;
  87.       argv++;
  88.       if(argc == 0)break;
  89.       strcat(cmdstr," ");
  90.    }
  91.    if(SendRexxMsg((STRPTR)"CBBS-1",0L,(STRPTR)cmdstr,0L)) {
  92.       printf("SendRexxMsg - command failed");
  93.       fclose(fdo);
  94.       exit(10);
  95.    }
  96.    while(1) {
  97.       Wait(rexxbit);
  98.       while(rexxmessage = GetRexxMsg(rexx_host,0L)) {
  99.          if(Arg = GetRexxCommand(rexxmessage)) {
  100.             if(!strncmp((char *)Arg,"SYSOP>",6)) {
  101.                ReplyRexxCommand(rexxmessage,0L,0L,0L);
  102.                goto done;
  103.             }
  104.             fprintf(fdo,"%s\n",Arg);
  105.             ReplyRexxCommand(rexxmessage,0L,0L,0L);
  106.          }
  107.          else {
  108.             FreeRexxCommand(rexxmessage);
  109.          }
  110.       }
  111.    }
  112. done:
  113.    fclose(fdo);
  114.    SendRexxMsg((STRPTR)"CBBS-1",0L,(STRPTR)"b",0L);
  115.    close_rexx();
  116. }
  117.